package com.leetcode.LC;

public class LC1184 {
    public int distanceBetweenBusStops(int[] distance, int start, int destination) {

        if (start==destination){
            return 0;
        }

        int[] ints = new int[distance.length * 2];
        for (int i = 0; i < distance.length; i++) {
            ints[i] = ints[i + distance.length] = distance[i];
        }

        /*for (int anInt : ints) {
            System.out.print(anInt+",");
        }
        System.out.println();*/

        if (start>destination){
            int x=start;
            start=destination;
            destination=x;
        }

        int tmp = start + distance.length, a = 0, b = 0;

        for (int i = start; i < destination; i++) {
            a += ints[i];
        }
        for (int i = destination; i < tmp; i++) {
            b += ints[i];
        }
        return Math.min(a, b);
    }

    public static void main(String[] args) {
        System.out.println(new LC1184().distanceBetweenBusStops(new int[]{7,10,1,12,11,14,5,0}, 7, 2));
    }
}
